Option Explicit

Dim doc
Set doc = application.ActiveDocument
If ValidateServer(doc) = 0 Then
    msgbox "Server validation failed."
Else
	Dim ischeck
	ischeck = doc.activeView.displayControl.section(4)
	ischeck = not ischeck
	doc.activeView.displayControl.section(4) = ischeck
End If

' Function to validate document
Private Function ValidateServer(doc)
    Dim key, licenseServer, licenseToken
    key = doc.Validate(0)
    Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
    licenseToken = licenseServer.GetToken(key)
    Set licenseServer = nothing
    'On Error Resume Next
    Err.Clear
    doc.Validate(licenseToken)
    If Err Then
        ValidateServer = 0    
    Else 
        ValidateServer = 1
    End If
End Function

